from selenium import webdriver
import unittest,time,traceback
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome("C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\chromedriver.exe")
url = "https://mail.qq.com/"
driver.get(url)
driver.maximize_window()
driver.switch_to.frame('login_frame')
# WebDriverWait(driver,5,0.5).until(lambda x: x.find_element_by_xpath('//*[text()="帐号密码登录"]')).click()
WebDriverWait(driver,5,0.5).until(lambda x: x.find_element_by_id('u')).send_keys('450837357')
WebDriverWait(driver,5,0.5).until(lambda x: x.find_element_by_id('p')).send_keys('wupujian@520')
driver.find_element_by_id('login_button').click()
WebDriverWait(driver,5,0.5).until(lambda x: x.find_element_by_id('composebtn')).click()
driver.switch_to.frame("mainFrame")
WebDriverWait(driver,5,0.5).until(lambda x: x.find_element_by_xpath(".//*[@id='toAreaCtrl']/div[2]/input")).send_keys('568582494@qq.com')
title = driver.find_element_by_id("subject")
title.send_keys("长点脑子")
driver.switch_to.frame(driver.find_element_by_class_name("qmEditorIfrmEditArea"))
# driver.switch_to(driver.find_element_by_tag_name("iframe"))
content = driver.find_element_by_tag_name("body")
content.send_keys("我啥时候有你的QQ，记得不，不记得就让你长长记性")
driver.switch_to.parent_frame()
sendButton = driver.find_element_by_link_text("发送")
sendButton.click()
print ("邮件内容已经填写完毕并触发“发送按钮”,发送成功")
time.sleep(5)
driver.quit()

